<?php
// +----------------------------------------------------------------------
// | 萤火商城系统 [ 致力于通过产品和服务，帮助商家高效化开拓市场 ]
// +----------------------------------------------------------------------
// | Copyright (c) 2017~2023 https://www.yiovo.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed 这不是一个自由软件，不允许对程序代码以任何形式任何目的的再发行
// +----------------------------------------------------------------------
// | Author: 萤火科技 <admin@yiovo.com>
// +----------------------------------------------------------------------
declare (strict_types=1);

namespace app\api\model;

use app\common\model\store\IndexType as IndexTypeModel;
use think\model\relation\HasOne;

/**
 * 商家记录表模型
 * Class Store
 * @package app\store\model
 */
class IndexType extends IndexTypeModel
{
    /**
     * 隐藏的字段
     * @var string[]
     */
    protected $hidden = [
        'sort',
        'is_delete',
        'create_time',
        'update_time'
    ];


    /**
     * 获取当前商城的基本信息
     * @return Store|array|null
     */
    public static function getInfo()
    {
        return static::detail(static::$storeId);
    }


    /**
     * 获取列表
     * @param array $param
     * @return \think\Paginator
     * @throws \think\db\exception\DbException
     */
    public function getIndeTypeList(array $param = []){
        $list = $this->where($this->getFilter($param))
            ->where('is_delete', '=', 0)
            ->where('parant_id', '=', 0)
            ->order(['sort', $this->getPk()])
            ->select();

        return $list;

    }

    
   /**
     * 根据param检索查询条件
     * @param array $param
     * @return array
     */
    private function getFilter(array $param = [])
    {
        // 默认查询条件
        $params = $this->setQueryDefaultValue($param, [
            'type' => '',    // 地址类型(10发货地址 20退货地址)
            'search' => '',   // 收货人姓名/联系电话
        ]);
        // 检索查询条件
        $filter = [];
        // $params['type'] > 0 && $filter[] = ['type', '=', $params['type']];
        !empty($params['search']) && $filter[] = ['name', 'like', "%{$params['search']}%"];
        return $filter;
    }

    public function getIndeTypeName(int $typeId){
        $list = $this->detail($typeId);
        return $list;

    }


     /**
     * 获取列表
     * @param array $param
     * @return \think\Paginator
     * @throws \think\db\exception\DbException
     */
    public function getIndeTypeList2(int $parant_id){
        $list = $this->where('is_delete', '=', 0)
            ->where('parant_id', '=',$parant_id)
            ->order(['sort', $this->getPk()])
            ->select();

        return $list;

    }

}
